<template>
  <el-container class="home-container">
    <el-header>
      后台管理系统
      <div class="right">
        <span class="user"> <i class="el-icon-user" />admin</span>
        <span class="logout" @click="logout"> <i class="el-icon-switch-button" />退出</span>
      </div>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu
          router
          :default-active="$route.fullPath"
          background-color="#313743"
          text-color="#fff"
          active-text-color="#409eff"
          unique-opened
        >
          <el-menu-item index="/home">
            <i class="el-icon-s-home"></i>
            <span slot="title">首页</span>
          </el-menu-item>
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-bank-card"></i>
              <span>栏目</span>
            </template>
            <el-menu-item index="/home/cate/add"><i class="el-icon-menu" />添加</el-menu-item>
            <el-menu-item index="/home/cate"><i class="el-icon-menu" />列表</el-menu-item>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-bank-card"></i>
              <span>内容</span>
            </template>
            <el-menu-item index="/home/content/add"><i class="el-icon-menu" />添加</el-menu-item>
            <el-menu-item index="/home/content"><i class="el-icon-menu" />列表</el-menu-item>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-setting"></i>
              <span>广告</span>
            </template>
            <el-menu-item index="/home/adv"> <i class="el-icon-menu" />广告位</el-menu-item>
            <el-menu-item index="/home/adv/content"
              ><i class="el-icon-menu" />广告内容</el-menu-item
            >
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <RouterView />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: 'Home',
  methods: {
    // 退出登录
    logout() {
      this.$confirm('确定退出登录？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          // 提示退出成功
          this.$message.success('退出登录成功')
          // 删除本地token
          sessionStorage.removeItem('token')
          // 跳转到登录页面
          this.$router.push('/login')
        })
        .catch(() => this.$message.info('已取消退出'))
    }
  }
}
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;
}

.el-header {
  display: flex;
  justify-content: space-between;
  background-color: #373d41;
  color: #fff;
  line-height: 60px;
  font-size: 20px;

  .right {
    font-size: 16px;

    span {
      & ~ span {
        margin-left: 20px;
      }

      i {
        margin-right: 10px;
      }
    }

    .logout {
      cursor: pointer;
      transition: all 0.35s;

      &:hover {
        color: #409eff;
      }
    }
  }
}

.el-aside {
  background-color: #313743;
  color: #fff;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-menu {
  border-right: none;
}
</style>
